﻿/*
 * Last review by   : Yaser
 * Last review date : JUL-20-09 
 */
using System;
using System.Collections;
using System.Collections.Generic;

namespace ERP.Business.DataTypes.BaseTypes
{
    /// <summary>
    /// Base Enumerator.
    /// used to implement collection base class.
    /// </summary>
    /// <typeparam name="T">Object type</typeparam>
    public class BaseEnumerator<T> : IEnumerator<T>
    {
        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="BaseEnumerator&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="enumerator">The enumerator.</param>
        public BaseEnumerator(IEnumerator<T> enumerator)
        {
            m_enumerator = enumerator;
        }

        #endregion

        #region Members

        private IEnumerator<T> m_enumerator;

        #endregion

        #region Properties

        /// <summary>
        /// Gets the current.
        /// </summary>
        /// <value>The current.</value>
        public T Current
        {
            get
            {
                return m_enumerator.Current;
            }
        }

        /// <summary>
        /// Gets the current.
        /// </summary>
        /// <value>The current.</value>
        object IEnumerator.Current
        {
            get
            {
                return Current;
            }
        }

        /// <summary>
        /// Gets the current.
        /// </summary>
        /// <value>The current.</value>
        T IEnumerator<T>.Current
        {
            get
            {
                return Current;
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            GC.SuppressFinalize(m_enumerator);
            GC.SuppressFinalize(this);
        }

        /// <summary>
        /// Advances the enumerator to the next element of the collection.
        /// </summary>
        /// <returns>
        /// true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.
        /// </returns>
        /// <exception cref="T:System.InvalidOperationException">The collection was modified after the enumerator was created. </exception>
        public bool MoveNext()
        {
            return m_enumerator.MoveNext();
        }

        /// <summary>
        /// Sets the enumerator to its initial position, which is before the first element in the collection.
        /// </summary>
        /// <exception cref="T:System.InvalidOperationException">The collection was modified after the enumerator was created. </exception>
        public void Reset()
        {
            m_enumerator.Reset();
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        void IDisposable.Dispose()
        {
            Dispose();
        }

        /// <summary>
        /// Advances the enumerator to the next element of the collection.
        /// </summary>
        /// <returns>
        /// true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.
        /// </returns>
        /// <exception cref="T:System.InvalidOperationException">The collection was modified after the enumerator was created. </exception>
        bool IEnumerator.MoveNext()
        {
            return MoveNext();
        }

        /// <summary>
        /// Sets the enumerator to its initial position, which is before the first element in the collection.
        /// </summary>
        /// <exception cref="T:System.InvalidOperationException">The collection was modified after the enumerator was created. </exception>
        void IEnumerator.Reset()
        {
            Reset();
        }

        #endregion
    }
}
